package air_cp5620.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class ProcessPassword {

	public static String encrypt(String pwd) throws NoSuchAlgorithmException{
		MessageDigest md=MessageDigest.getInstance("MD5");
		md.update(pwd.getBytes());
		byte[] result=md.digest();
		
		return byte2Str(result);		
	}

	private static String byte2Str(byte[] b) { 

		String hs = ""; 
		String stmp = ""; 
		
		for (int n = 0;n < b.length;n++) { 
			stmp = (Integer.toHexString(b[n] & 0XFF)); 
			if (stmp.length() == 1) {
				   hs = hs + "0"+ stmp;			
			}
			else { 
				   hs = hs + stmp;
			}
			
			if ( n < (b.length-1)) {
				   hs = hs + "";
			}
		}
		 
		return hs;
	} 

}
